package com.tianzehua.protobuf;

/**
 * 该测试的意义在于，将对象序列化成字节数组的话，就可以在网络中传输了
 * @author tianzehua
 * @date 2019/03/14
 */
public class ProtoBufTest {

    public static void main(String[] args) throws  Exception{

        /* 使用protobuf来构建对象  */
        DataInfo.Student student =  DataInfo.Student.newBuilder()
                .setName("张三")
                .setAge(20)
                .setAdress("北京")
                .build();

        /* 将其转换为字节数组 */
        byte[] bytes = student.toByteArray();

        /* 再将其转译过来 */
        DataInfo.Student student2 = DataInfo.Student.parseFrom(bytes);

        System.out.println(student2.getName());
        System.out.println(student2.getAdress());
        System.out.println(student2.getAge());
    }
}
